<!--title-->
<div class="mnav1">
	<div class="m_nav">
		<div class="nav_left">
			<em class="home_icon"><?=$this->sys_name?></em><span>&nbsp;&gt;&nbsp;</span><font><?=$this->title?></font>
		</div>
	</div>
</div>

<div class="content-table2">
	<div class="content-table-title"><b><?=$this->title?></b>：&nbsp;&nbsp;&nbsp;&nbsp;[<?=$this->data['contract_sid']?>] <?=$this->data['client_name']?></div>
<br />
<div class="form-edit-task">
<form action="/contracts/invoice-apply-submit" method="post" name="form1" enctype="multipart/form-data" onsubmit="submitform(this);return false;">
<table border="0" width="100%">
	<tr>
		<td align="right">申请票种：</td>
		<td align="left">&nbsp;<input type="radio" name="invoice_type" id="invoice_type_1" value="1" <?php if(1==$this->data['invoice_type']){echo "checked='checked'";}?> />&nbsp;<label for="invoice_type_1">专用发票</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="invoice_type" id="invoice_type_2" value="2" <?php if(2==$this->data['invoice_type']){echo "checked='checked'";}?> />&nbsp;<label for="invoice_type_2">普通发票</label><font color="red"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*</font></td>
	</tr>
	<tr>
		<td align="right">公司全称：</td>
		<td align="left">&nbsp;<input type="text" placeholder="公司全称" name="company_name" id="company_name" value="<?=$this->data['company_name']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">纳税人识别号：</td>
		<td align="left">&nbsp;<input type="text" placeholder="纳税人识别号" name="tax_number" id="tax_number" value="<?=$this->data['tax_number']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">注册地址及电话：</td>
		<td align="left">&nbsp;<input type="text" placeholder="注册地址及电话" name="register_address" id="register_address" value="<?=$this->data['register_address']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">开户银行：</td>
		<td align="left">&nbsp;<input type="text" placeholder="开户银行" name="bank_name" id="bank_name" value="<?=$this->data['bank_name']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">开户银行账号：</td>
		<td align="left">&nbsp;<input type="text" placeholder="开户银行账号" name="bank_number" id="bank_number" value="<?=$this->data['bank_number']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">联系人：</td>
		<td align="left">&nbsp;<input type="text" placeholder="联系人" name="contact_name" id="contact_name" value="<?=$this->data['contact_name']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">联系电话：</td>
		<td align="left">&nbsp;<input type="text" placeholder="联系电话" name="tel" id="tel" value="<?=$this->data['tel']?>" style="width: 300px"><font color="red"> *</font></td>
	<tr>
		<td align="right">收件地址：</td>
		<td align="left">&nbsp;<input type="text" placeholder="收件地址" name="contact_address" id="contact_address" value="<?=$this->data['contact_address']?>" style="width: 300px"><font color="red"> *</font></td>
	</tr>
	<tr>
		<td align="right">营业执照复印件：</td>
		<td align="left">&nbsp;
			<?php if($this->data['img1']):?>
				<a href="/upload/signers/<?=$this->data['img1']?>" target="_blank"><img src="/upload/signers/<?=$this->data['img1']?>" height="70" alt="点击看大图" title="点击看大图" /></a>
				&nbsp;&nbsp;&nbsp;&nbsp;
			<?php endif;?>
			<input type="file" name="img1" id="img1" /><font color="red"> *</font><input type="hidden" name="old_img1" value="<?=$this->data['img1']?>" /><input type="hidden" name="is_img1" id="is_img1" value="<?=$this->data['img1']?1:0?>" /></td>
	</tr>
	<tr>
		<td align="right">开户许可证复印件：</td>
		<td align="left">&nbsp;
			<?php if($this->data['img3']):?>
				<a href="/upload/signers/<?=$this->data['img3']?>" target="_blank"><img src="/upload/signers/<?=$this->data['img3']?>" height="70" alt="点击看大图" title="点击看大图" /></a>
				&nbsp;&nbsp;&nbsp;&nbsp;
			<?php endif;?>
			<input type="file" name="img3" id="img3" /><font color="red"> *</font><input type="hidden" name="old_img3" value="<?=$this->data['img3']?>" /><input type="hidden" name="is_img3" id="is_img3" value="<?=$this->data['img3']?1:0?>" /></td>
	</tr>
	<tr>
		<td align="right">一般纳税人认定书：</td>
		<td align="left">&nbsp;
			<?php if($this->data['img4']):?>
				<a href="/upload/signers/<?=$this->data['img4']?>" target="_blank"><img src="/upload/signers/<?=$this->data['img4']?>" height="70" alt="点击看大图" title="点击看大图" /></a>
				&nbsp;&nbsp;&nbsp;&nbsp;
			<?php endif;?>
			<input type="file" name="img4" id="img4" /><font color="red"> *</font><input type="hidden" name="old_img4" value="<?=$this->data['img4']?>" /><input type="hidden" name="is_img4" id="is_img4" value="<?=$this->data['img4']?1:0?>" /></td>
	</tr>
</table>
<br /><br />
<div class="content-table">
<table border="1" width="100%">
	<tr>
		<th>产品名称</th>
		<th>发票内容</th>
		<th>版本</th>
		<th>数量</th>
		<th>合同总金额</th>
		<th>已开票金额</th>
		<th>本次开票金额</th>
	</tr>
	<?php if($this->skus):?>
	<?php foreach($this->skus as $sku_arr):?>
	<tr>
		<td><?=$sku_arr['product_name']?><input type="hidden" name="product_name_<?=$sku_arr['cs_id']?>" value="<?=$sku_arr['product_name']?>" /></td>
		<td>
			<select name="sku_invoice_name_<?=$sku_arr['cs_id']?>" id="sku_invoice_name_<?=$sku_arr['cs_id']?>">
				<?php if(isset($this->invoice_names[$sku_arr['product_id']])):?>
				<?php foreach($this->invoice_names[$sku_arr['product_id']] as $invoice_name_id => $invoice_name_val):?>
				<option value="<?=$invoice_name_id?>" <?php if($invoice_name_id==$sku_arr['invoice_name_id']){echo "selected='selected'";}?>><?=$invoice_name_val?></option>
				<?php endforeach;?>
				<?php endif;?>
			</select>
		</td>
		<td>
			<select name="sku_invoice_version_<?=$sku_arr['cs_id']?>" id="sku_invoice_version_<?=$sku_arr['cs_id']?>">
				<?php if(isset($this->invoice_versions[$sku_arr['product_id']])):?>
				<?php foreach($this->invoice_versions[$sku_arr['product_id']] as $invoice_version_id => $invoice_version_val):?>
				<option value="<?=$invoice_version_id?>" <?php if($invoice_version_id==$sku_arr['invoice_version_id']){echo "selected='selected'";}?>><?=$invoice_version_val?></option>
				<?php endforeach;?>
				<?php endif;?>
			</select>
		</td>
		<td><?=$sku_arr['quantity']?><input type="hidden" name="quantity_<?=$sku_arr['cs_id']?>" value="<?=$sku_arr['quantity']?>" /></td>
		<td><?=$sku_arr['actual_pay']?><input type="hidden" name="actual_pay_<?=$sku_arr['cs_id']?>" value="<?=$sku_arr['actual_pay']?>" /></td>
		<td><?=$sku_arr['invoice_applied']?$sku_arr['invoice_applied']:"0.00"?></td>
		<td><input type="text" name="apply_value_<?=$sku_arr['cs_id']?>" id="apply_value_<?=$sku_arr['cs_id']?>" value="<?=$sku_arr['actual_pay']-$sku_arr['invoice_applied']?>" maxValue="<?=$sku_arr['actual_pay']-$sku_arr['invoice_applied']?>" style="width: 80px" /></td>
	</tr>
	<?php endforeach;?>
	<?php endif;?>
</table>
</div>

<table border="0" width="100%">
	<tr>
		<td colspan="2" align="center"><br><br><input type="hidden" name="stype" value="<?=$this->stype?>" /><input type="hidden" name="contract_id" value="<?=$this->data['contract_id']?>" /><input type="hidden" name="contract_sid" value="<?=$this->data['contract_sid']?>" /><input type="hidden" name="signer_id" value="<?=$this->data['signer_id']?>" /><input type="button" class="buttonlong" value="提交开票申请" onclick="submitform();return false;" /></td>
	</tr>
</table>
<br /><br />
</form>
</div>
<br/><br/>
</div>

<script>
$('input').bind('keyup', function () {
	if($(this).attr('maxValue')){
		if(isNaN($(this).val())){
			alert('请输入数字');
			return;
		}
		var maxValue = Number($(this).attr('maxValue'));
		var val = Number($(this).val());
		if(val > maxValue){
			alert('超出最大值，不可超过实际发生金额');
			$(this).val(maxValue);
		}
	}
});


<?php if($this->msg):?>
alert("<?=$this->msg?>, 信息提交失败, 请修改后再次提交。");
<?php endif;?>

function submitform() 
{
	if( !$(':radio[name=invoice_type]:checked').length )
	{
		alert("申请票种不能为空。");
		return false;
	}else if( document.form1.company_name.value.length == 0 )
	{
		alert("公司全称不能为空。");
		return false;
	}else if( document.form1.tax_number.value.length == 0 )
	{
		alert("纳税人识别号不能为空。");
		return false;
	}else if( document.form1.register_address.value.length == 0 )
	{
		alert("注册地址及电话不能为空。");
		return false;
	}else if( document.form1.bank_name.value.length == 0 )
	{
		alert("开户银行不能为空。");
		return false;
	}else if( document.form1.bank_number.value.length == 0 )
	{
		alert("开户银行账号不能为空。");
		return false;
	}else if( document.form1.contact_name.value.length == 0 )
	{
		alert("联系人不能为空。");
		return false;
	}else if( document.form1.tel.value.length == 0 )
	{
		alert("联系电话不能为空。");
		return false;
	}else if( document.form1.contact_address.value.length == 0 )
	{
		alert("收件地址不能为空。");
		return false;
	}
	
	if(document.form1.is_img1.value == 0)
	{
		var file = $("#img1").val();
		if (file == "") {
			alert("请上传营业执照复印件，支持格式：JPG或PNG");
			return false;
		} else {
			//检验文件类型是否正确
			var exec = (/[.]/.exec(file)) ? /[^.]+$/.exec(file.toLowerCase()) : '';
			if (exec != "png" && exec != "jpg" && exec != "jpeg") {
				alert("上传的营业执照复印件格式不对，支持格式：JPG或PNG");
				return false;
			}
		}
	}
	
	if(document.form1.is_img3.value == 0)
	{
		var file = $("#img3").val();
		if (file == "") {
			alert("请上传开户许可证复印件，支持格式：JPG或PNG");
			return false;
		} else {
			//检验文件类型是否正确
			var exec = (/[.]/.exec(file)) ? /[^.]+$/.exec(file.toLowerCase()) : '';
			if (exec != "png" && exec != "jpg" && exec != "jpeg") {
				alert("上传的开户许可证复印件格式不对，支持格式：JPG或PNG");
				return false;
			}
		}
	}
	
	if(document.form1.is_img4.value == 0)
	{
		var file = $("#img4").val();
		if (file == "") {
			alert("请上传一般纳税人认定书，支持格式：JPG或PNG");
			return false;
		} else {
			//检验文件类型是否正确
			var exec = (/[.]/.exec(file)) ? /[^.]+$/.exec(file.toLowerCase()) : '';
			if (exec != "png" && exec != "jpg" && exec != "jpeg") {
				alert("上传的一般纳税人认定书格式不对，支持格式：JPG或PNG");
				return false;
			}
		}
	}
	
	form1.submit();
}
</script>
